﻿using System;
using System.Threading;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Micua.Core.Caching.Interception;

namespace Micua.UnitTest
{
    [TestClass]
    public class CachingCallHandlerTester
    {
        [TestMethod]
        public void CachingResult()
        {
            var container = new UnityContainer()
                .AddNewExtension<Interception>()
                .RegisterType<IPostService, PostService>();//声明UnityContainer并注册IOutput
            container
                .Configure<Interception>()
                .SetInterceptorFor<IPostService>(new InterfaceInterceptor());
            var service = container.Resolve<IPostService>();
            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine(service.GetSomthing());
            }
            //测试通过 2014年1月10日 11:24:19 By iceStone
        }
    }
    public interface IPostService
    {
        string GetSomthing();
    }

    public class PostService : IPostService
    {
        [CachingCallResult(3)]
        public string GetSomthing()
        {
            return Guid.NewGuid().ToString();
        }
    }
}
